<?php
class FlipToggle extends FormElement {
	
	private $onValue;
	private $onText;
	private $offValue;
	private $offText;
	
	public function __construct($elementId, $labelText, $onText = 'On', $offText = 'Off', $onValue = 'on', $offValue = 'off') {
	
		parent::__construct($elementId, $labelText);
		
		$this->onText = $onText;
		$this->offText = $offText;
		$this->onValue = $onValue;
		$this->offValue = $offValue;
	}
	
	protected function renderElement() {
		
		$hiddenLabelClass = '';
		if ($this->labelVisibility == Label::$labelHidden) {
			$hiddenLabelClass = 'class="ui-hidden-accessible"';
		}
		
		if (strcmp($this->onValue, $this->getDefaultValue()) == 0) {
			$onSelected = 'selected="selected"';
			$offSelected = '';
		} else if (strcmp($this->$offValue, $this->getDefaultValue()) == 0) {
			$offSelected = 'selected="selected"';
			$onSelected = '';
		} else {
			$onSelected = '';
			$offSelected = '';
		}
	
		echo '<label for="', $this->elementId, '" ', $hiddenLabelClass, ' >', $this->labelText, '</label>';
		echo '<select data-role="slider" name="', $this->elementId, '" ', $this->formatAttributes(), '>';
		echo '<option value="', $this->offValue, '" ', $offSelected, ' >', $this->offText, '</option>';
		echo '<option value="', $this->onValue, '" ', $onSelected, ' >', $this->onText, '</option>';
		echo '</select>';
	}
}
?>